package data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
	private static Connection conn = null;
	
	static{
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("Driver loaded");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}			
	}
	
	public static Connection getInstance(){
		if (conn == null){
			try {
				conn =DriverManager.getConnection("jdbc:mysql://localhost/mygalaxy?useUnicode=true&characterEncoding=gbk", "root", "tiancai");
				System.out.println("Database connected");
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		else 
			return conn;
		return conn;
		
		
	}
}
